﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PetaPoco;

namespace WebAppMatrix.DAL.Security
{
    public class MatrixUser : BaseRepository<Entity.Security.MatrixUser>
    {
        public MatrixUser(Data.MatrixData database) : base(database) { }

        public Entity.Security.MatrixUser GetEntityByLoginName(string loginName)
        {
            string sentenceName = "MatrixUser_GetEntityByName";
            string sentence = Configuration.SqlConfigManager.GetSqlSentence(sentenceName);
            return Database.FirstOrDefault<Entity.Security.MatrixUser>(sentence, loginName);
        }

        public Page<Entity.Security.MatrixUser> GetPageEntity(long page, long rows, string keyword)
        {
            string sentenceName = "MatrixUser_GetPageEntity";
            string sentence = Configuration.SqlConfigManager.GetSqlSentence(sentenceName);
            Sql sql = Sql.Builder.Append(sentence);
            if (!string.IsNullOrWhiteSpace(keyword))
            {
                sql.Append(" AND LoginName like '%" + keyword + "%'");
            }

            return Database.Page<Entity.Security.MatrixUser>(page, rows, sql);
        }
    }
}
